//
// Created by Administrator on 2019/12/10.
//
#include <iostream>
#include <cstring>
#include <string>
#include <stdlib.h>
#include <unistd.h>
//#include "windows.h"
//#include "winsock.h"
//#include "mysql.h"

using namespace std;








void exercise3(){

    int i, *pi1=&i, *pi2;
    double d, *pd1=&d, *pd2;
    pi2=pi1+1;
    pd2=pd1+1;
    cout<<(pi2-pi1)<<", "<<(pd2-pd1)<<endl;
//    cout<<(int)pi2-(int)pi1<<', '<<(int)pd2-(int)pd1<<endl;
//    cout << (int)pi2 - (int)pi1 << endl;
}

/**
 * 普通输出打印
 */
void exercise2(){
    double d = 1850;
    double d2 = 2219;
    double d3 = 150000 ;    //本金
    double finalMoney = d3 * d2 / d;
    cout << "最终金额-->" << finalMoney << ",赚取金额-->" << finalMoney - d3 << endl;

}


/**
 * 根据num返回对应的空格数字符串
 * @param num
 * @param str
 * @return
 */
string getStrByNumber(int num, string str) {
    string spaceStr;
    for (int i = 0; i < num; ++i) {
        spaceStr += str;
    }
    return spaceStr;
}

/**
 * 打印
 * @param x 表示打印的高度
 */
void printDiamond(int x) {
    if (x < 0) {
        cout << "无法打印";
    } else {
        int lineCount = 2 * x - 1;
        int diamondNum = 1;
        for (int index = 0; index < lineCount; index++) {
            string space = getStrByNumber(abs(lineCount - x - index), " ");
            string diamond = getStrByNumber(diamondNum, "*");
            cout << space << diamond << endl;
            if(x > (index + 1)) {
                diamondNum += 2;
            } else {
                diamondNum -= 2;
            }
        }
    }
}

void exercise1(){
    cout << "打印菱形!!，请输入菱形行高!" << endl;
//    int x ;
//    cin >> x ;
    for (int i = 1; i < 50; ++i) {
        cout << "------------------------------------------->行高" << i << "<-----------------------------------" << endl;
        printDiamond(i);

    }
}


